/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.schedule.core.service;

import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import info.peigen.hotpot.component.schedule.facade.command.ScheduleNodeServiceFacade;
import info.peigen.hotpot.component.schedule.facade.command.order.ScheduleNodeCreateOrder;
import info.peigen.hotpot.component.schedule.facade.command.order.ScheduleNodeDeleteOrder;
import info.peigen.hotpot.component.schedule.facade.command.order.ScheduleNodeEditOrder;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleNodeCreateResult;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleNodeDeleteResult;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleNodeEditResult;
import org.noear.solon.annotation.Component;

/**
 * <b>(ScheduleNodeService)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/1/6
 */
@Component
public class ScheduleNodeService extends AbstractScheduleService implements ScheduleNodeServiceFacade {
    @Override
    public ScheduleNodeCreateResult create(ScheduleNodeCreateOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new ScheduleNodeCreateResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleNodeCreateProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleNodeCreateResultProcessor, scheduleNodeStoreProcessor);
            }
        });
        return (ScheduleNodeCreateResult) serviceContext.getResult();
    }

    @Override
    public ScheduleNodeEditResult edit(ScheduleNodeEditOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new ScheduleNodeEditResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleNodeActiveProcessor, scheduleNodeEditProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleNodeEditResultProcessor, scheduleNodeStoreProcessor);
            }
        });
        return (ScheduleNodeEditResult) serviceContext.getResult();
    }

    @Override
    public ScheduleNodeDeleteResult delete(ScheduleNodeDeleteOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order).result(new ScheduleNodeDeleteResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors();
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(scheduleNodeDeleteProcessor, scheduleNodeDeleteResultProcessor);
            }
        });
        return (ScheduleNodeDeleteResult) serviceContext.getResult();
    }
}
